home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / Perl_WWW_Utilities / perlMIF_beta2 / mif / mif_dict.pl < prev    next >
Encoding:
Perl Script  |  1994-05-18  |  4.4 KB  |  137 lines

  1. ##---------------------------------------------------------------------------##
  2. ##  File:
  3. ##      mif_dict.pl
  4. ##  Author:
  5. ##      Earl Hood       ehood@convex.com
  6. ##  Description:
  7. ##    This file is defines the "mif_dict" perl package.  It defines
  8. ##    routines to handle the Dictionary via MIFread_mif() defined in
  9. ##    the "mif" package.
  10. ##---------------------------------------------------------------------------##
  11. ##  Copyright (C) 1994  Earl Hood, ehood@convex.com
  12. ##
  13. ##  This program is free software; you can redistribute it and/or modify
  14. ##  it under the terms of the GNU General Public License as published by
  15. ##  the Free Software Foundation; either version 2 of the License, or
  16. ##  (at your option) any later version.
  17. ## 
  18. ##  This program is distributed in the hope that it will be useful,
  19. ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ##  GNU General Public License for more details.
  22. ##  
  23. ##  You should have received a copy of the GNU General Public License
  24. ##  along with this program; if not, write to the Free Software
  25. ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. ##---------------------------------------------------------------------------##
  27.  
  28. require 'mif/mif.pl' || die "Unable to require mif.pl\n";
  29.  
  30. package mif_dict;
  31.  
  32. ##--------------------------------------------##
  33. ## Add Dictionary function to %MIFToken array ##
  34. ##--------------------------------------------##
  35. $mif'MIFToken{'Dictionary'} = 'Dictionary';
  36.  
  37. ##-------------------------------##
  38. ## Dictionary associative arrays ##
  39. ##-------------------------------##
  40. %OKWord        = ();
  41.  
  42. ##------------------------##
  43. ## Import 'mif' variables ##
  44. ##------------------------##
  45. $MStore        = $mif'MStore;
  46. $MOpen        = $mif'MOpen;
  47. $MClose        = $mif'MClose;
  48. $MLine        = $mif'MLine;
  49. $mso        = $mif'mso;
  50. $msc        = $mif'msc;
  51. $stb        = $mif'stb;
  52. $ste        = $mif'ste;
  53. $como        = $mif'como;
  54.  
  55.                 ##---------------##
  56.                 ## Main Routines ##
  57.                 ##---------------##
  58. ##---------------------------------------------------------------------------
  59. ##    MIFwrite_dict() outputs the Dictionary as defined by the
  60. ##    associative arrays.
  61. ##
  62. ##    Usage:
  63. ##        &'MIFwrite_dict(FILEHANDLE);
  64. ##
  65. sub main'MIFwrite_dict {
  66.     local($handle, $l) = @_;
  67.     local($i0, $i1, $i2) = (' ' x $l, ' ' x (1+$l), ' ' x (2+$l));
  68.  
  69.     print $handle $i0, $mso, 'Dictionary', "\n";
  70.     foreach (sort keys %OKWord) {
  71.     print $handle $i2, $mso, 'OKWord ', $stb, $_, $ste, $msc, "\n"
  72.         if $_;
  73.     }
  74.     print $handle $i0, $msc, " $como end of Dictionary\n";
  75. }
  76. ##---------------------------------------------------------------------------##
  77. ##    MIFget_dict_words() returns a sorted array of all words defined
  78. ##    in the dictionary.
  79. ##
  80. ##    Usage:
  81. ##        @words = &'MIFget_dict_words();
  82. ##
  83. sub main'MIFget_dict_words {
  84.     return sort keys %OKWord;
  85. }
  86. ##---------------------------------------------------------------------------##
  87. ##    MIFreset_dict() resets the associative arrays for the dictionary.
  88. ##
  89. ##    Usage:
  90. ##        &'MIFreset_dict();
  91. ##
  92. sub main'MIFreset_dict {
  93.     undef %OKWord;
  94. }
  95. ##---------------------------------------------------------------------------##
  96.                 ##--------------##
  97.                 ## Mif Routines ##
  98.                 ##--------------##
  99. ##---------------------------------------------------------------------------##
  100. ##    The routines definded below are all registered in the %MIFToken         ##
  101. ##    array for use in the read_mif() routine.  There purpose is to         ##
  102. ##    store the information contained in the dictionary.             ##
  103. ##---------------------------------------------------------------------------##
  104.  
  105. ##---------------------------------------------------------------------------
  106. ##    Dictionary() is the token routine for 'Dictionary'.
  107. ##    It sets/restores token routines depending upon mode.
  108. ##
  109. sub mif'Dictionary {
  110.     local($token, $mode, *data) = @_;
  111.     if ($mode == $MOpen) {
  112.     ($_fast, $_noidata) = ($mif'fast, $mif'no_import_data);
  113.     ($mif'fast, $mif'no_import_data) = (1, 1);
  114.     @_orgfunc = @mif'MIFToken{
  115.                 'OKWord'
  116.             };
  117.     @mif'MIFToken{
  118.         'OKWord'
  119.     } = (
  120.         "mif_dict'OKWord"
  121.     );
  122.     } elsif ($mode == $MClose) {
  123.     @mif'MIFToken{
  124.         'OKWord'
  125.     } = @_orgfunc;
  126.     ($mif'fast, $mif'no_import_data) = ($_fast, $_noidata);
  127.     }
  128. }
  129. ##---------------------------------------------------------------------------
  130. sub OKWord {
  131.     local($token, $mode, *data) = @_;
  132.     $data =~ /^\s*$stb([^$ste]*)$ste.*$/o;
  133.     $OKWord{$1} = 1;
  134. }
  135. ##---------------------------------------------------------------------------
  136. 1;
  137.